package com.sugar.subscribe.course.module.business.controller.admin.home;

import com.sugar.subscribe.course.framework.common.pojo.CommonResult;
import com.sugar.subscribe.course.module.business.controller.admin.home.vo.StatisticsRespVO;
import com.sugar.subscribe.course.module.business.dal.mysql.coach.CoachMapper;
import com.sugar.subscribe.course.module.business.dal.mysql.order.BizOrderMapper;
import com.sugar.subscribe.course.module.business.dal.mysql.user.BizUserMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.sugar.subscribe.course.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 数据统计")
@RestController
@RequestMapping("/business/statistics")
@Validated
public class HomeController {

    @Resource
    private BizUserMapper bizUserMapper;
    @Resource
    private CoachMapper coachMapper;
    @Resource
    private BizOrderMapper bizOrderMapper;

    @GetMapping("/get")
    @Operation(summary = "统计数据")
    public CommonResult<StatisticsRespVO> statistics() {
        StatisticsRespVO statisticsRespVO = new StatisticsRespVO();

        statisticsRespVO.setUserCount(bizUserMapper.selectCount())
                .setCoachCount(coachMapper.selectCount())
                .setOrderCount(bizOrderMapper.selectCount())
                .setGrossProfit(bizOrderMapper.selectGrossProfit());

        return success(statisticsRespVO);
    }
}
